home *** CD-ROM | disk | FTP | other *** search
/ Aminet 20 / Aminet 20 (1997)(GTI - Schatztruhe)[!][Aug 1997].iso / Aminet / comm / www / HTP.lha / HTP / source / varstore.h < prev    next >
C/C++ Source or Header  |  1997-06-21  |  4KB  |  141 lines

  1. /*
  2. //
  3. // varstore.h
  4. //
  5. // Variable store functions
  6. //
  7. // Copyright (c) 1995-96 Jim Nelson.  Permission to distribute
  8. // granted by the author.  No warranties are made on the fitness of this
  9. // source code.
  10. // Amiga version - 1997 - Geert Bevin
  11. //
  12. */
  13.  
  14. #ifndef VARSTORE_H
  15. #define VARSTORE_H
  16.  
  17. #include <exec/types.h>
  18.  
  19. /*
  20. // maximum length for the variable name and the variables value
  21. */
  22. #define MAX_VARNAME_LEN         (256)
  23. #define MAX_VARVALUE_LEN        (512)
  24.  
  25. /*
  26. // variable destructor callback ... set to NULL if no callback required when
  27. // destroyed
  28. */
  29. typedef void (*VAR_DESTRUCTOR)(const char *name, const char *value,
  30.     uint type, uint flag, void *param);
  31.  
  32. /*
  33. // a variable held in the store
  34. */
  35. typedef struct tagVARIABLE
  36. {
  37.     struct tagVARIABLE  *next;
  38.     char                name[MAX_VARNAME_LEN];
  39.     char                value[MAX_VARVALUE_LEN];
  40.     uint                type;
  41.     uint                flag;
  42.     void                *param;
  43.     VAR_DESTRUCTOR      destructor;
  44. } VARIABLE;
  45.  
  46. /*
  47. // variable store structure
  48. //
  49. // parent and child refers to scope ... when traversing the chain for a
  50. // particular macro, always look to parent scope if not found in current
  51. */
  52. typedef struct tagVARSTORE
  53. {
  54.     struct tagVARSTORE      *parent;
  55.     struct tagVARSTORE      *child;
  56.     VARIABLE                *lastVariable;
  57.     VARIABLE                **variableHashTable;
  58. } VARSTORE;
  59.  
  60. /*
  61. // statistics for performance measurement
  62. */
  63. #if DEBUG
  64. extern uint variableLookups;
  65. extern uint variableCacheHits;
  66. extern uint variableStringCompares;
  67. extern uint variableMissedStringCompares;
  68. extern uint variableHashCalcs;
  69. #endif
  70.  
  71. /*
  72. // GetVariableType() will return this value if the variable is not found
  73. */
  74. #define VAR_TYPE_UNKNOWN        ((uint) -1)
  75.  
  76. /*
  77. // GetVariableFlag() will return this value if the variable is not found
  78. */
  79. #define VAR_FLAG_UNKNOWN        ((uint) -1)
  80.  
  81. /*
  82. // initialize a VARSTORE
  83. */
  84. BOOL InitializeVariableStore(VARSTORE *varstore);
  85.  
  86. /*
  87. // destroys a variable store and ALL child scope stores
  88. */
  89. void DestroyVariableStore(VARSTORE *varstore);
  90.  
  91. /*
  92. // Push, pop, and get current varstore context ... note that for pop and
  93. // get, simply passing a variable store somewhere in the context will get
  94. // or pop the topmost one, and for push it will find the topmost context
  95. // before adding the new context
  96. */
  97. void PushVariableStoreContext(VARSTORE *parent, VARSTORE *varstore);
  98. VARSTORE *PopVariableStoreContext(VARSTORE *varstore);
  99. VARSTORE *PeekVariableStoreContext(VARSTORE *varstore);
  100.  
  101. /*
  102. // add a variable to a store ... the store will keep its
  103. // own copy of the variable kept, no need to maintain name and
  104. // value once added
  105. //
  106. // Set destructor to NULL if no additional processing required before
  107. // destroying the variable.  Otherwise, pass a pointer to a function.
  108. //
  109. // Returns FALSE if unable to add variable into the store
  110. */
  111. BOOL StoreVariable(VARSTORE *varstore, const char *name, const char *value,
  112.     uint type, uint flag, void *param, VAR_DESTRUCTOR destructor);
  113.  
  114. /*
  115. // Returns TRUE if variable found in store (case-insensitive)
  116. */
  117. BOOL VariableExists(VARSTORE *varstore, const char *name);
  118.  
  119. /*
  120. // A variable's destructor will be called from the context of these
  121. // functions
  122. */
  123. BOOL RemoveVariable(VARSTORE *varstore, const char *name);
  124. void ClearVariableList(VARSTORE *varstore);
  125.  
  126. /*
  127. // Get variable information ... returns NULL for GetVariableValue(),
  128. // VAR_TYPE_UNKNOWN for GetVariableType(), and VAR_FLAG_UNKNOWN for
  129. // GetVariableFlag() if variable not in list
  130. //
  131. // GetVariableParam() returns NULL if not found ... since this is a valid
  132. // return value, caller should really use VariableExists() first!
  133. */
  134. const char *GetVariableValue(VARSTORE *varstore, const char *name);
  135. uint GetVariableType(VARSTORE *varstore, const char *name);
  136. uint GetVariableFlag(VARSTORE *varstore, const char *name);
  137. void *GetVariableParam(VARSTORE *varstore, const char *name);
  138.  
  139. #endif
  140.  
  141.